package cn.topevery.garden.dal.dao.impl;

import cn.topevery.garden.dal.dao.BotanyFileDao;
import cn.topevery.garden.entity.po.BotanyFile;
import cn.topevery.garden.framework.base.BaseDaoImpl;
import hw.topevery.framework.db.CommandType;
import hw.topevery.framework.db.entity.SqlQueryMate;
import hw.topevery.framework.db.enums.ScriptConditionEnum;
import hw.topevery.framework.entity.DbCsp;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 
 *
 * @author code-generate
 * @date 2021-08-26
 */
@Repository
public class BotanyFileDaoImpl extends BaseDaoImpl<BotanyFile> implements BotanyFileDao {
    @Override
    public <P extends DbCsp> List<BotanyFile> getSearch(P para) {
        return null;
    }

    @Override
    public List<BotanyFile> getListByPid(Integer pid, Integer type) {
        String table = "t_botany_file tpc";

        String columns = "tpc.*";

        SqlQueryMate sqlQueryMate = new SqlQueryMate(table).setColumns(columns);
        sqlQueryMate
                .where(true, "tpc.c_db_status", ScriptConditionEnum.Eq, 0)
                .where(true, "tpc.c_main_id", ScriptConditionEnum.Eq, pid)
                .where(true, "tpc.c_type", ScriptConditionEnum.Eq, type)
        ;
        return selectList(sqlQueryMate, BotanyFile.class);
    }

    @Override
    public void deleteById(Integer id) {
        String sql = "delete from t_botany_file where c_main_id = " + id;
        run(sql, CommandType.Text, dbCommand -> {
            dbCommand.executeNonQuery();
        });
    }

}
